package com.example.Lezedata.ui.activity.address;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.example.Lezedata.R;

import bid.Bid;

public class AddressListVcCell extends FrameLayout {

    private TextView name;
    private TextView address;
    private TextView default_selected;
    private TextView delete;
    private TextView edit;
    private TextView phone;

    public Bid.ExpressAddress expressAddress;

    public interface ClassListener{
        void delete(Bid.ExpressAddress expressAddress);
        void edit(Bid.ExpressAddress expressAddress);
    }
    public ClassListener listener;

    public static AddressListVcCell newInstance(Context context) {
        AddressListVcCell fragment = (AddressListVcCell) LayoutInflater.from(context).inflate(R.layout.address_list_cell,null,false);
        return fragment;
    }

    public AddressListVcCell(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        findView();
    }

    void findView() {
        name = findViewWithTag("name");
        address = findViewWithTag("address");
        default_selected = findViewWithTag("default_selected");
        phone = findViewWithTag("phone");
        edit = findViewWithTag("edit");
        delete = findViewWithTag("delete");
        delete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null){
                    listener.delete(expressAddress);
                }
            }
        });

        edit.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener != null){
                    listener.edit(expressAddress);
                }
            }
        });
    }

    public void setExpressAddress(Bid.ExpressAddress expressAddress) {
        this.expressAddress = expressAddress;
        name.setText(String.format("%s%s",expressAddress.getLastName(),expressAddress.getFirstName()));
        address.setText(String.format("%s,%s,%s",expressAddress.getState(),expressAddress.getCity(),expressAddress.getAddress()));
        phone.setText(expressAddress.getPhone());

//        if (expressAddress.getDefault() == Bid.SetDefault.SD_BY_DEFAULT){
//            default_selected.setVisibility(VISIBLE);
//        }else {
//            default_selected.setVisibility(INVISIBLE);
//        }
    }
}
